<template>
  <div class="app-container">
    <el-table v-loading="loading" :data="historyList">
      <el-table-column align="center" label="样本编码" prop="operateContent"/>
      <el-table-column :formatter="typeFormat" align="center" label="操作类型" prop="operatorType"/>
      <el-table-column align="center" label="操作人" prop="operator"/>
      <el-table-column align="center" label="操作时间" prop="operatorTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operatorTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listHistory } from '@/api/biobank/tubeHistory'

export default {
  name: 'TubeHistory',
  components: {},
  props: {
    tubeId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 冻存管历史 表格数据
      historyList: [],
      // 单据类型字典
      typeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tubeId: undefined
      }
    }
  },
  created() {
    this.getDicts('activiti_stock_type').then(response => {
      this.typeOptions = response.data
    })
    this.queryParams.tubeId = this.tubeId
    this.getList()
  },
  methods: {
    /** 查询冻存管历史 列表 */
    getList() {
      this.loading = true
      listHistory(this.queryParams).then(response => {
        this.historyList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    typeFormat(row, column) {
      return this.selectDictLabel(this.typeOptions, row.operatorType)
    }
  },
  watch: {
    tubeId(newValue, oldValue) {
      this.historyList = []
      this.queryParams.tubeId = newValue
      this.getList()
    }
  }
}
</script>
